#include <cstdio>
#include <cstring>

const int max_d = 20;

int main(void) {
  int kase;  
  scanf("%d", &kase);
  while (kase--) {
    int d, i;    
    while (scanf("%d %d", &d, &i) == 2) {
      int n = 1;
      for (int t = 0; t < d - 1; t++) {
        if (i % 2) {
          n = n * 2;
          i = (i + 1) / 2;
        }
        else {
          n = n * 2 + 1;
          i = i / 2;
        }
      }
      printf("%d\n", n);
    }
  }
  scanf("%d", &kase);
  
  return 0;
}
